package com.sykj.cloud.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sykj.cloud.common.log.annotation.Log;
import com.sykj.cloud.common.log.enums.LogUserType;
import com.sykj.cloud.common.security.annotation.PreAuthorize;
import com.sykj.cloud.system.domain.MemberParameter;
import com.sykj.cloud.system.service.IMemberParameterService;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.page.TableDataInfo;

/**
 * 会员参数 Controller
 *
 * @author mr.will
 * @date 2021-03-30
 */
@RestController
@RequestMapping("/member_parameter")
public class MemberParameterController extends BaseController
{
    @Autowired
    private IMemberParameterService memberParameterService;

    /**
     * 新增会员参数
     */
    @PreAuthorize(hasPermi = "system:member_parameter:add")
    @Log(title = "会员参数 ", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MemberParameter memberParameter)
    {
        int i=memberParameterService.insertMemberParameter(memberParameter);
        if(i==-1){
            return AjaxResult.error("该会员参数code已经存在，不能再次新增");
        }
        return toAjax(i);
    }

    /**
     * 修改会员参数
     */
    @PreAuthorize(hasPermi = "system:member_parameter:edit")
    @Log(title = "会员参数 ", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MemberParameter memberParameter)
    {
        return toAjax(memberParameterService.updateMemberParameter(memberParameter));
    }

    /**
     * 删除会员参数
     */
    @PreAuthorize(hasPermi = "system:member_parameter:remove")
    @Log(title = "会员参数 ", logUserType = LogUserType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(memberParameterService.deleteMemberParameterByIds(guids));
    }

    /**
     * 获取会员参数 详细信息
     */
    @PreAuthorize(hasPermi = "system:member_parameter:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(memberParameterService.getMemberParameterById(guid));
    }

    /**
     * 导出会员参数 列表
     */
    @PreAuthorize(hasPermi = "system:member_parameter:export")
    @Log(title = "会员参数 ", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MemberParameter memberParameter) throws IOException
    {
        List<MemberParameter> list = memberParameterService.listMemberParameters(memberParameter);
        ExcelUtil<MemberParameter> util = new ExcelUtil<MemberParameter>(MemberParameter.class);
        util.exportExcel(response, list, "member_parameter");
    }

    /**
     * 查询会员参数 列表
     */
    @PreAuthorize(hasPermi = "system:member_parameter:list")
    @GetMapping("/list")
    public TableDataInfo list(MemberParameter memberParameter)
    {
        startPage();
        List<MemberParameter> list = memberParameterService.listMemberParameters(memberParameter);
        return getDataTable(list);
    }
}
